//==============================================================================
#include "CBomba.h"
//==============================================================================
CBomba::CBomba():CObjetoAnimado() {
    this->OldTime=0;
    this->OldTimeExplosion=0;
    this->Type = ENTITY_TYPE_BOMBA;
    this->CurrentIndex=0;
    this->TieneQueExplotar=false;
}
//==============================================================================
CBomba::~CBomba() {
}
//------------------------------------------------------------------------------
void CBomba::OnLoop() {
    long tics;

    if (!this->TieneQueExplotar) {
        CurrentIndex=0;
        Type = ENTITY_TYPE_BOMBA;
        tics=SDL_GetTicks();
        if (this->OldTime + 10000 < tics) {
            this->TieneQueExplotar=true;
            tics=SDL_GetTicks();
            this->OldTime = tics;
            this->OldTimeExplosion = tics;
        }
        else
            this->CurrentIndex=0;
    }

    else{// (this->TieneQueExplotar){
        this->CurrentIndex=1;
        tics=SDL_GetTicks();
        this->Explotar();
        if (this->OldTimeExplosion + 5000 < tics) {
            this->OldTimeExplosion = tics;
            this->OldTime = 0;
            this->Inactive=true;
            //this->TieneQueExplotar=false;
        }
    }

	//if (!this->Inactive)
        CObjetoAnimado::OnLoop();
}
//------------------------------------------------------------------------------
void CBomba::Explotar(){
    int NewX, NewY, radio=5;//rango de la explosion;
    this->Type = ENTITY_TYPE_EXPLOSION;
    for(int i = 0;i < ObjectList.size();i++)  {
        for (int j=(-1)*radio;j<=radio;j++){
            //if (j==0) continue;
            NewX=this->X + (j * TILE_SIZE);
            NewY=this->Y + (j * TILE_SIZE);
            this->PosValidObject(ObjectList[i], NewX, NewY,false);
            NewX=this->X + (j * TILE_SIZE);
            NewY=this->Y ;
            this->PosValidObject(ObjectList[i], NewX, NewY,false);
            NewX=this->X;
            NewY=this->Y + (j * TILE_SIZE);
            this->PosValidObject(ObjectList[i], NewX, NewY,false);
            NewX=this->X;
            NewY=this->Y;
            this->PosValidObject(ObjectList[i], NewX, NewY,false);
		}
    }
}
//==============================================================================

